﻿using System.Data;
using System.Data.SqlClient;

public class CustomerTransactionsDAL
{
    dbConnection db = new dbConnection();
    public  DataTable Load(CustomerTransactionsBO CustomerTransaction)
    {

        SqlConnection cn = null;
        SqlCommand cmd = null;
        DataSet dSet = null;
        SqlDataAdapter sda = null;

        try
        {
            cn = new SqlConnection();
            cn.ConnectionString = db.GetCS();
            cmd = new SqlCommand();
            cmd.Connection = cn;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "Select  PayerAccountId,Amount,PayeeAccountId,TransactionDate,TransactionID   from [Transactions]  where  PayeeAccountId=@AccountId ";
            cmd.Parameters.AddWithValue("@AccountId", CustomerTransaction.AccountId);

            dSet = new DataSet();
            sda = new SqlDataAdapter(cmd);

            sda.Fill(dSet, "Transactions");

            return dSet.Tables["Transactions"];

        }

        catch
        {

            throw;

        }

        finally
        {

            dSet.Dispose();

            sda.Dispose();

            cn.Close();

            cn.Dispose();

        }
    }

    public  DataTable LoadDebit(CustomerTransactionsBO CustomerTransactionDebit)
    {

        SqlConnection cn = null;
        SqlCommand cmd = null;
        DataSet dSet = null;
        SqlDataAdapter sda = null;

        try
        {
            cn = new SqlConnection();
            cn.ConnectionString = db.GetCS();
            cmd = new SqlCommand();
            cmd.Connection = cn;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "Select PayerAccountId,Amount,PayeeAccountId,TransactionDate,TransactionID   from [Transactions]  where  PayerAccountId=@AccountId ";
            cmd.Parameters.AddWithValue("@AccountId", CustomerTransactionDebit.AccountId);

            dSet = new DataSet();
            sda = new SqlDataAdapter(cmd);

            sda.Fill(dSet, "Transactions");

            return dSet.Tables["Transactions"];

        }

        catch
        {

            throw;

        }

        finally
        {

            dSet.Dispose();

            sda.Dispose();

            cn.Close();

            cn.Dispose();

        }
    }

}

